@using System.Text.Json.Nodes
@using Elsa.Api.Client.Resources.WorkflowDefinitions.Models
@using Elsa.Studio.Workflows.Domain.Models
@using Elsa.Studio.Workflows.Shared.Args
@using Microsoft.AspNetCore.Components.Forms
@inherits BackendComponentBase

<ThemedComponentWrapper>
    <WorkflowDefinitionEditor DefinitionId="@DefinitionId"
                              WorkflowDefinitionExecuted="WorkflowDefinitionExecuted"
                              WorkflowDefinitionVersionSelected="WorkflowDefinitionVersionSelected"
                              ActivitySelected="ActivitySelected"
                              />
</ThemedComponentWrapper>

@code
{
    /// The ID of the workflow definition to edit.
    [Parameter] public string DefinitionId { get; set; } = default!;

    /// <summary>An event that is invoked when a workflow definition has been executed.</summary>
    /// <remarks>The ID of the workflow instance is provided as the value to the event callback.</remarks>
    [Parameter] public EventCallback<string> WorkflowDefinitionExecuted { get; set; }

    /// Gets or sets the event that occurs when the workflow definition version is updated.
    [Parameter] public EventCallback<WorkflowDefinition> WorkflowDefinitionVersionSelected { get; set; }

    /// Gets or sets the event triggered when an activity is selected.
    [Parameter] public EventCallback<JsonObject> ActivitySelected { get; set; }

    /// Gets the currently selected activity ID.
    public string? SelectedActivityId => WorkflowDefinitionEditor.SelectedActivityId;

    private WorkflowDefinitionEditor WorkflowDefinitionEditor { get; set; } = default!;

    /// Gets the currently selected workflow definition version.
    public WorkflowDefinition? GetSelectedWorkflowDefinitionVersion() => WorkflowDefinitionEditor.GetSelectedWorkflowDefinitionVersion();
}